package com.dps.omc.strategy;

import java.util.List;
import java.util.Map;

import com.dps.omc.model.AgentNode;
import com.dps.omc.model.TemplateHandler;
import com.dps.omc.service.ITemplateHandlerService;
import com.dps.omc.strategy.handler.IStepHandler;
import com.dps.omc.sys.SpringBeanUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



/**
 * @author lp 创建于 2015年7月1日
 */
@Component
public class StepManager {
	@Autowired
	private ITemplateHandlerService templateHandlerService;
	@Autowired
	private SpringBeanUtils springBeanUtils;
	
	public void execute(String templateId, AgentNode agentNode, Map<String, String> data)
	{
		List<TemplateHandler> steps = templateHandlerService.findList("templateId", templateId);//查到所有
		StepChain chain = new StepChain();
		for(TemplateHandler step:steps)
		{
			IStepHandler handle  = (IStepHandler) springBeanUtils.getBean(step.getClazz());
			StepParser parser = new StepParser(step,handle);
			chain.addStep(parser);//List<IStep>
		}
		chain.process(agentNode,data, chain);
	}
}
